from boot import QApplication, Qt, InfoBar, InfoBarPosition, GlobalWidget


__all__ = ["high_dpi", "popup"]


def high_dpi(cls):
    # 高分辨率屏适应
    QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
    QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
    QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
    def wrapper(*args, **kwargs):
        return cls(*args, **kwargs)
    return wrapper

def popup(method):
    def wrapper(self, *i_args, **kwargs):
        info, status = method(self, *i_args, **kwargs)
        if status:
            InfoBar.success(
                title='',
                content=info,
                orient=Qt.Horizontal,
                isClosable=True,
                position=InfoBarPosition.TOP,
                duration=5000,
                parent=GlobalWidget.root
            )
        else:
            InfoBar.warning(
                title='',
                content=info,
                orient=Qt.Horizontal,
                isClosable=True,
                position=InfoBarPosition.TOP,
                duration=5000,
                parent=GlobalWidget.root
            )
        return None
    return wrapper